import publicForm from "@/components/public/el-form.vue"; //弹框form
import CustomDialog from "@/components/stationProductionPage/TensionManage/TensionRealTime/processDetail/index.vue";
import publicForm1 from "@/components/public/el-forms.vue"; //弹框form

import {
    getTensioningProcess, //详情


} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
        "fCompanyid",
        "fCompanyname",
        "modelType", "getList"
    ],
    data() {
        return {
            WBSRow: {},
            WBSShow: false,

            visible: "",
            title: null,
            isLock: false,
            btnStatus: [],
            positionObj: [],
            dialogHeight: null,
            activeIndex: "1",

            tableData: [],

            currentDetail: null,
            fCompanynames: null,
            fCompanyids: null,
            processDetail: null


        };
    },
    components: {
        publicForm,
        CustomDialog,
        publicForm1
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        modelType: {
            handler(newVal) {
                if (newVal) {
                    this.modelTypes = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {


                    // this.edit(newVal);
                }

            },
            immediate: true,
        },

        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    // fStatus
                    this.getDetail({
                        fCompanyid: this.currentDetail.fCompanyid,
                        beamId: this.currentDetail.fBeamid,
                    })


                }
            },

            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {

                    this.fCompanyids = newVal

                }
            },
            immediate: true,
        },
        fCompanyname: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanynames = newVal

                }
            },
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        this.btnShow = true
        this.getHeight();
    },
    methods: {
        refreshList() {},
        WBSDialog() {
            this.WBSShow = false;
        },
        openDialog(row) {
            console.log(row);
            this.processDetail = row;
            this.WBSShow = true;

        },
        getWBS(data) { //获取材料信息
            this.formData.fConstructionsite = data.fLongname //施工部位
            this.formData.fConstructionsiteid = data.fNodeid //施工部位id

        },
        // 折叠面板
        changeCollapse(e) {
            console.log(this.activeNames, e);
        },
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.6 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },

        edit() {
            this.closeFormData = this.$options.data.call(this).closeFormData;
        },

        // 查看列表---行合并
        objectSpanMethod({
            row,
            column,
            rowIndex,
            columnIndex
        }) {
            if (
                columnIndex === 0 ||
                columnIndex === 1 ||
                columnIndex === 2 ||
                columnIndex === 19
            ) {
                if (rowIndex % 6 === 0) {
                    return {
                        rowspan: 6,
                        colspan: 1,
                    };
                } else {
                    return {
                        rowspan: 0,
                        colspan: 0,
                    };
                }
            } else if (
                columnIndex === 3 ||
                columnIndex === 11 ||
                columnIndex === 12 ||
                columnIndex === 13 ||
                columnIndex === 14 ||
                columnIndex === 15 ||
                columnIndex === 16 ||
                columnIndex === 17 ||
                columnIndex === 18
            ) {
                if (rowIndex % 3 === 0) {
                    return {
                        rowspan: 3,
                        colspan: 1,
                    };
                } else {
                    return {
                        rowspan: 0,
                        colspan: 0,
                    };
                }
            }
            return row, column, rowIndex, columnIndex;
        },
        // 详情
        getDetail(obj) {
            // var that = this
            this.loading = true;
            getTensioningProcess(obj).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;

                    var data = res.data.tensioningProcess;

                    data.map((item) => {
                        // 预警级别
                        if (item.fWarninglevel == 0) {
                            item.fWarninglevelText = "正常";
                            item.btnType = "success";
                        } else if (item.fWarninglevel == 1) {
                            item.fWarninglevelText = "一级";
                            item.btnType = "plain";
                        } else if (item.fWarninglevel == 2) {
                            item.fWarninglevelText = "二级";
                            item.btnType = "warning";
                        } else if (item.fWarninglevel == 3) {
                            item.fWarninglevelText = "三级";
                            item.btnType = "danger";
                        } else if (item.fWarninglevel == 4) {
                            item.fWarninglevelText = "四级";
                            item.btnType = "purple";
                        }
                        // 超张百分比
                        if (item.fOvertensionratewarninglevel == 0) {
                            item.OvertensionrateBtnType = "success";
                        } else if (item.fOvertensionratewarninglevel == 1) {
                            item.OvertensionrateBtnType = "plain";
                        } else if (item.fOvertensionratewarninglevel == 2) {
                            item.OvertensionrateBtnType = "warning";
                        } else if (item.fOvertensionratewarninglevel == 3) {
                            item.OvertensionrateBtnType = "danger";
                        } else if (item.fOvertensionratewarninglevel == 4) {
                            item.OvertensionrateBtnType = "purple";
                        }
                        //延伸量误差
                        if (item.fElongationdeviationwarninglevel == 0) {
                            item.ElongationdeviationBtnType = "success";
                        } else if (item.fElongationdeviationwarninglevel == 1) {
                            item.ElongationdeviationBtnType = "plain";
                        } else if (item.fElongationdeviationwarninglevel == 2) {
                            item.ElongationdeviationBtnType = "warning";
                        } else if (item.fElongationdeviationwarninglevel == 3) {
                            item.ElongationdeviationBtnType = "danger";
                        } else if (item.fElongationdeviationwarninglevel == 4) {
                            item.ElongationdeviationBtnType = "purple";
                        }
                        // 回缩量
                        if (item.fRetractionwarninglevel == 0) {
                            item.RetractionBtnType = "success";
                        } else if (item.fRetractionwarninglevel == 1) {
                            item.RetractionBtnType = "plain";
                        } else if (item.fRetractionwarninglevel == 2) {
                            item.RetractionBtnType = "warning";
                        } else if (item.fRetractionwarninglevel == 3) {
                            item.RetractionBtnType = "danger";
                        } else if (item.fRetractionwarninglevel == 4) {
                            item.RetractionBtnType = "purple";
                        }
                        // 持荷时间
                        if (item.fHoldingtimewarninglevel == 0) {
                            item.HoldingtimeBtnType = "success";
                        } else if (item.fHoldingtimewarninglevel == 1) {
                            item.HoldingtimeBtnType = "plain";
                        } else if (item.fHoldingtimewarninglevel == 2) {
                            item.HoldingtimeBtnType = "warning";
                        } else if (item.fHoldingtimewarninglevel == 3) {
                            item.HoldingtimeBtnType = "danger";
                        } else if (item.fHoldingtimewarninglevel == 4) {
                            item.HoldingtimeBtnType = "purple";
                        }
                    });
                    this.tableData = data
                } else {
                    this.loading = false;
                }
            });
        },

    },
};